package com.ruoyi.life.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.life.domain.FeApartmentCancelBill;
import com.ruoyi.life.service.IFeApartmentCancelBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 公寓退租账单Controller
 *
 * @author cjie
 * @date 2022-09-26
 */
@Api(tags = " 公寓退租账单")
@RestController
@RequestMapping("/feApartmentCancelBill")
public class FeApartmentCancelBillController extends BaseController {
    @Autowired
    private IFeApartmentCancelBillService feApartmentCancelBillService;

    /**
     * 查询公寓退租账单列表
     */
    @ApiOperation(value="查询公寓退租账单列表", notes="查询公寓退租账单列表")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:list")
    @GetMapping("/list")
    public TableDataInfo list(FeApartmentCancelBill feApartmentCancelBill) {
        startPage();
        List<FeApartmentCancelBill> list = feApartmentCancelBillService.selectFeApartmentCancelBillList(feApartmentCancelBill);
        return getDataTable(list);
    }

    /**
     * 导出公寓退租账单列表
     */
    @ApiOperation(value="导出公寓退租账单列表", notes="导出公寓退租账单列表")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:export")
    @Log(title = "公寓退租账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeApartmentCancelBill feApartmentCancelBill) throws IOException {
        List<FeApartmentCancelBill> list = feApartmentCancelBillService.selectFeApartmentCancelBillList(feApartmentCancelBill);
        ExcelUtil<FeApartmentCancelBill> util = new ExcelUtil<FeApartmentCancelBill>(FeApartmentCancelBill.class);
        util.exportExcel(response, list, "公寓退租账单数据");
    }
    /**
     * 获取公寓退租账单详细信息
     */
    @ApiOperation(value="获取公寓退租账单详细信息", notes="获取公寓退租账单详细信息")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(feApartmentCancelBillService.selectFeApartmentCancelBillById(id));
    }

    @ApiOperation(value="确认通知企业", notes="确认通知企业")
    @PostMapping(value = "/cancelBillNotice")
    public AjaxResult cancelBillNotice(@RequestBody FeApartmentCancelBill feApartmentCancelBill) {
        return AjaxResult.success(feApartmentCancelBillService.updateFeApartmentCancelBillState(feApartmentCancelBill));
    }

    /**
     * 新增公寓退租账单
     */
    @ApiOperation(value="新增公寓退租账单", notes="新增公寓退租账单")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:add")
    @Log(title = "公寓退租账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeApartmentCancelBill feApartmentCancelBill) {
        return toAjax(feApartmentCancelBillService.insertFeApartmentCancelBill(feApartmentCancelBill));
    }

    /**
     * 修改公寓退租账单
     */
    @ApiOperation(value="修改公寓退租账单", notes="修改公寓退租账单")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:edit")
    @Log(title = "公寓退租账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeApartmentCancelBill feApartmentCancelBill) {
        return toAjax(feApartmentCancelBillService.updateFeApartmentCancelBill(feApartmentCancelBill));
    }

    /**
     * 删除公寓退租账单
     */
    @ApiOperation(value="删除公寓退租账单", notes="删除公寓退租账单")
    @ApiImplicitParam(name = "ids", value = "公寓退租账单ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:feApartmentCancelBill:remove")
    @Log(title = "公寓退租账单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(feApartmentCancelBillService.deleteFeApartmentCancelBillByIds(ids));
    }
}
